package server.main.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import server.main.config.cache.MybatisPlusRedisCache;
import server.main.pojo.Account;
import server.main.pojo.FunctionPage;
import server.main.pojo.Permission;
import server.main.pojo.Role;


import java.util.List;

/**
 * @auther MingHsZzz
 * @Date 2022/9/7-12:33
 */
//前端权限的传输，
@Mapper
@CacheNamespace(implementation = MybatisPlusRedisCache.class)
public interface PermissionMapper extends BaseMapper<Permission> {

    @Select("select m.id, m.pattern, r.id as rid, r.name as rname, r.nameZh as rnameZh from permission m left join role_permission mr on m.id = mr.permission_id  left join role r on mr.role_id = r.id")
    public List<Permission> getAllpermission();


    @Select("")
    public List<Permission> getPermissionByUser(String jobnum);

    @Select("select * from permission")
    public List<Permission> getAllpermissions();

    @Select("select r.id,r.name,r.nameZh from role r left join role_permission rp on r.id = rp.role_id where rp.permission_id = #{id}")
    public List<Role> getRoles(Integer id);

    /**
     * 根据id获取urls
     * @param id permissionid
     * @return 页面list
     */
    @Select("SELECT fp.id,fp.url,fp.pagedescribe,fp.pagename,fp.title FROM function_page AS fp\n" +
            "LEFT JOIN permission_functionpage AS pf ON fp.id = pf.function_page_id\n" +
            "LEFT JOIN permission AS p ON p.id = pf.permission_id\n" +
            "WHERE p.id = #{id}")
    public List<FunctionPage> getUrlsByPermissionId(Integer id);

}
